<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>申请详细</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.searchText"
            ><el-button
              slot="append"
              icon="el-icon-search"
              @click="getIn1List()"
            ></el-button> </el-input
        ></el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible = true"
            >申请</el-button
          >
        </el-col>
      </el-row>
      <el-divider><i class="el-icon-s-check"></i></el-divider>
      <!-- 申请表区域 -->
      <el-table :data="in1list" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="申请编号" prop="Inno1"></el-table-column>
        <el-table-column label="物品类别" prop="Object1"></el-table-column>
        <el-table-column label="重量/吨" prop="Ton1"></el-table-column>
        <el-table-column label="公司名称" prop="Company"></el-table-column>
        <el-table-column label="月份" prop="Inmon1"></el-table-column>
        <el-table-column label="日期" prop="Inday1"></el-table-column>
        <el-table-column fixed="right" label="操作" width="95">
          <template>
            <el-tooltip content="编辑" placement="bottom">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                circle
                @click="editDialogVisible = true"
              ></el-button>
            </el-tooltip>
            
            <el-tooltip content="删除" placement="bottom">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                circle
                @click="deleteDialogVisible = true"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        small
        layout="prev, pager, next"
        :total="50"
        :current-page="queryInfo.pagenum"
        :page-size="queryInfo.pagesize"
      >
      </el-pagination>
    </el-card>

    <!-- 添加物流信息 -->
    <el-dialog
      title="申请表"
      :visible.sync="addDialogVisible"
      width="50%"
      @close="addDialogClose()"
    >
      <!--内容主体区域-->
      <el-form
        :model="addForm"
        :rules="addFormRulers"
        ref="addFormRef"
        label-width="110px"
      >
        <el-form-item label="申请编号" prop="inno1">
          <el-input v-model="addForm.inno1"></el-input>
        </el-form-item>
        <el-form-item label="物品类别" prop="object1">
          <el-input v-model="addForm.object1"></el-input>
        </el-form-item>
        <el-form-item label="重量/吨" prop="ton1">
          <el-input v-model="addForm.ton1"></el-input>
        </el-form-item>
        <el-form-item label="公司名称" prop="company">
          <el-input v-model="addForm.piece1"></el-input>
        </el-form-item>
        <el-form-item label="月份" prop="inmon1">
          <el-input v-model="addForm.inmon1"></el-input>
        </el-form-item>
        <el-form-item label="日期" prop="inday1">
          <el-input v-model="addForm.inday1"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addin1">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 修改申请信息 -->
    <el-dialog
      title="修改申请信息"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="updateDialogClose()"
    >
    <el-form
        :model="updateForm"
        :rules="updateFormRulers"
        ref="updateFormRef"
        label-width="110px"
      >
        <el-form-item label="申请编号" prop="inno1">
          <el-input v-model="addForm.inno1"></el-input>
        </el-form-item>
        <el-form-item label="物品类别" prop="object1">
          <el-input v-model="addForm.object1"></el-input>
        </el-form-item>
        <el-form-item label="重量/吨" prop="ton1">
          <el-input v-model="addForm.ton1"></el-input>
        </el-form-item>
        <el-form-item label="公司名称" prop="company">
          <el-input v-model="addForm.piece1"></el-input>
        </el-form-item>
        <el-form-item label="月份" prop="inmon1">
          <el-input v-model="addForm.inmon1"></el-input>
        </el-form-item>
        <el-form-item label="日期" prop="inday1">
          <el-input v-model="addForm.inday1"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="showEditDialog"
          >确定修改</el-button
        >
      </span>
    </el-dialog>

    <!-- 删除申请 -->
    <el-dialog
      title="删除申请信息"
      :visible.sync="deleteDialogVisible"
      width="50%"
      @close="deleteDialogClose()"
    >
    <el-form
        :model="deleteForm"
        :rules="deleteFormRulers"
        ref="deleteFormRef"
        label-width="110px"
      >
        <el-form-item label="申请编号" prop="inno1">
          <el-input v-model="deleteForm.inno1"></el-input>
        </el-form-item>
        
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="deleteDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="showDeleteDialog"
          >确定删除</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
 

<script>
export default {
  name: "in1",
  data() {
    //获取申请表的参数
    return {
      queryInfo: {
        searchText: "",
        pagenum: 1,
        pagesize: 2,
      },
      in1list: [],
      total: 0,
      // 控制对话框显示与隐藏
      addDialogVisible: false,
      //添加申请的表单
      addForm: {
        inno1: "",
        object1: "",
        ton1: "",
        company: "",
        inmon1: "",
        inday1: ""
      },
      //添加表单的验证对象
      addFormRulers: {
        inno1: [{ required: true, message: "请输入编号", trigger: "blur" }],
        object1: [{ required: true, message: "请输入物品名", trigger: "blur" }],
        ton1: [{ required: true, message: "请输入重量", trigger: "blur" }],
        company: [{ required: true, message: "请输入名称", trigger: "blur" }],
        inmon1: [{ required: true, message: "请输入月份", trigger: "blur" }],
        inday1: [{ required: true, message: "请输入日期", trigger: "blur" }]
      },
      //控制修改用户对话框的显示与隐藏
      editDialogVisible: false,
      //修改申请的表单
      updateForm: {
        inno1: "",
        object1: "",
        ton1: "",
        company: "",
        inmon1: "",
        inday1: "",
      },
      //添加表单的验证对象
      updateFormRulers: {
        inno1: [{ required: true, message: "请输入编号", trigger: "blur" }],
        object1: [{ required: true, message: "请输入物品名", trigger: "blur" }],
        ton1: [{ required: true, message: "请输入重量", trigger: "blur" }],
        company: [{ required: true, message: "请输入名称", trigger: "blur" }],
        inmon1: [{ required: true, message: "请输入月份", trigger: "blur" }],
        inday1: [{ required: true, message: "请输入日期", trigger: "blur" }]
      },
      // 控制对话框显示与隐藏
      deleteDialogVisible: false,
      //删除申请的表单
      deleteForm: {
        inno1: "",
      },
      //添加表单的验证对象
      deleteFormRulers: {
        inno1: [{ required: true, message: "请输入编号", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getIn1List();
  },
  methods: {
    async getIn1List() {
      const { data: res } = await this.$http.get("/in1", {
        parmas: this.queryInfo,
      });
      if (res.code != 20000) {
        return this.$message.error("获取用户列表失败");
      } else {
        this.in1list = res.data.value;
        this.total = res.data.total;
        console.log(res);
      }
    },
    // 监听对话框是否关闭
   addDialogClose() {
      this.$refs.addFormRef.resetFields();
    },
    updateDialogClose(){
      this.$refs.updateFormRef.resetFields();
    },
    deleteDialogClose(){
      this.$refs.deleteFormRef.resetFields();
    },
    // 点击按钮进行校验
    addin1() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (valid) {
          const { data: res } = await this.$http.post(
            "/in1",
            this.addForm
          );
          console.log(res);
          if (res.code != 20000) {
            this.$message.error("添加申请失败");
          } else {
            this.$message.success("添加申请成功");
            this.addDialogVisible = false;
            // 刷新申请信息
            this.getIn1List();
          }
        } else {
          return;
        }
      });
    },
    //显示编辑用户的对话框
    showEditDialog() {
      this.$refs.updateFormRef.validate(async (valid) => {
        if (valid) {
          const { data: res } = await this.$http.post(
            "/in1/update",
            this.updateForm
          );
          console.log(res);
          if (res.code != 20000) {
            this.$message.error("修改申请失败");
          } else {
            this.$message.success("修改申请成功");
            this.editDialogVisible = false;
            // 刷新物流表
            this.getIn1List();
          }
        } else {
          return;
        }
      });
    },
    // 显示删除用户的对话框
     showDeleteDialog() {
      this.$refs.deleteFormRef.validate(async (valid) => {
        if (valid) {
          const { data: res } = await this.$http.post(
            "/in1/delete",
            this.deleteForm
          );
          console.log(res);
          if (res.code != 20000) {
            this.$message.error("删除申请失败");
          } else {
            this.$message.success("删除申请成功");
            this.deleteDialogVisible = false;
            // 刷新申请信息
            this.getIn1List();
          }
        } else {
          return;
        }
      });
    },
  },
};
</script>

<style>
.el-breadcrumb {
  margin-bottom: 20px;
  font-size: 12px;
}

.el-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0) !important;
}
</style>